package com.offcn.test;

import sun.misc.Unsafe;

/**
 * Unsafe类操作数组
 */
public class UnsafeTest3 {
    public static void main(String[] args) {
        Unsafe unsafe = UnsafeUtil.getUnsafe();
        String[] names = {"卡卡西","鸣人","佐助","小樱"};
        Object firstName = unsafe.getAndSetObject(names, Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, null);
        System.out.println("FirstName:"+firstName);
        unsafe.putObject(names,Unsafe.ARRAY_BOOLEAN_BASE_OFFSET+Unsafe.ARRAY_OBJECT_INDEX_SCALE,"漩涡鸣人");
        Object secondName = unsafe.getObject(names,Unsafe.ARRAY_BOOLEAN_BASE_OFFSET+Unsafe.ARRAY_OBJECT_INDEX_SCALE);
        System.out.println("SecondName:"+secondName);
    }
}
